<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>自动补足六位编码</title>
<link type="text/css" href="css/bootstrap.css" rel="stylesheet" />
<script type="text/javascript" src="js/jq.js"></script>
<script type="text/javascript" >
$(function(){
	$("#btn_fill").click(function(){
		var old_str = $("#old").val();
		var obj = old_str.split("\n");
		var i=0;
		var err = "";
		while(i<obj.length)
		{
			if(!isNaN(obj[i]) && obj[i] != "" && obj[i] != 0 &&　obj[i].length <= 6)
			{
				while(obj[i].length<6)
				{
					obj[i] = '0' + obj[i];
				}
				i++;
			}
			else
			{
				err += obj[i]+"\n";
				obj.splice(i,1);
			}
		}
		obj = obj.join("\n");
		$("#fill").val(obj);
		if (err != "")
		{
			$("#err").show();
			$("#err").html('以下为输入格式不正确的数据：\n'+err);
		}
	});
	$("#btn_merger").click(function(){
		obj = $("#fill").val();
		obj = obj.split("\n");
		$("#merger").val(obj);
	});
});
</script>
</head>
<body>
<div class="container">
<fieldset>
<legend>自动补足六位编码</legend>
	<table>
		<tr>
			<td>
				<textarea rows="15" id="old"></textarea>
			</td>
			<td align="center">
				<div style="width:50px;font-size:12px;">少于6位的数字前自动补0</div>
				<button id="btn_fill" class="btn" >转换</button>
			</td>
			<td>
				<textarea rows="15" id="fill"></textarea>
			</td>
			<td align="center">
				<div style="width:50px;font-size:12px;">用逗号","分隔转后结果</div>
				<button id="btn_merger" class="btn">转换</button>
			</td>
			<td>
				<textarea rows="15" id="merger"></textarea>
			</td>
		</tr>
		<tr>
			<td>
				<textarea rows="15" id="err" style="display:none;color:red"></textarea>
			</td>
		</tr>
	</table>
</fieldset>
</div>
</body>
</html>